package com.huarui.quotation.lucene;

import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.ewaf.framework.lucene.DocumentBuilder;
import org.ewaf.framework.model.IDataObject;

import com.huarui.quotation.model.Quotation;

public class QuotationDocumentBuilder implements DocumentBuilder {

	@Override
	public Document buildDocument(IDataObject obj) {

		Quotation  quotation = (Quotation)obj;
		Document  document= new Document();
		
		
		
		/**
		 * 搜索条件
		 */
		document.add(new Field("source", quotation.getSource().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
		/**
		 * TODO : 名字是否需要模糊搜索
		 */
		document.add(new Field("name", quotation.getName(), Field.Store.YES, Field.Index.ANALYZED));
		document.add(new Field("code", quotation.getCode(), Field.Store.YES, Field.Index.NOT_ANALYZED));
		
		document.add(new Field("gmtCreate", DateTools.timeToString(quotation.getGmtCreate().getTime() , DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.NOT_ANALYZED ));
		document.add(new Field("gmtLastQuotation", DateTools.timeToString(quotation.getGmtLastQuotation().getTime() , DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.NOT_ANALYZED ));
		document.add(new Field("gmtLastSold", DateTools.timeToString(quotation.getGmtLastSold().getTime() , DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.NOT_ANALYZED ));
		document.add(new Field("gmtModify", DateTools.timeToString(quotation.getGmtModify().getTime() , DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.NOT_ANALYZED ));
		/**
		 * 附带内容
		 */
		document.add(new Field("id", quotation.getId().toString(),Field.Store.YES,Field.Index.NO));
		
		
		
		
		return document;
	}

}
